<?php if ($current_user['User']['role'] != 'spectator') : ?>
<span class="left">
	<?php if (isset($times[$task['Task']['id']])) : ?>
		<?php
			if ($times[$task['Task']['id']]['Time']['status'] != 'pause')
				$minutes = floor(time()/60) - $times[$task['Task']['id']]['Time']['start'] - $times[$task['Task']['id']]['Time']['pause'];
			else
				$minutes = floor(time()/60) - $times[$task['Task']['id']]['Time']['finish'];
		?>
		<span class="minutes" style="display: none;"><?php echo $minutes; ?></span>
		<span class="time left" style="background: white; padding: 0 4px;">
			<?php echo $date->minutesToTime($minutes); ?>
		</span>
		<?php if ($times[$task['Task']['id']]['Time']['status'] == 'play') : ?>
		<a class="left" href="/times/pause/<?php echo $task['Task']['id']; ?>/<?php echo base64_encode($this->params['url']['url']); ?>" title="Pause">
			<img src="/img/control_pause.png" style="height: 18px; margin: 2px 4px 0 1px;"/>
		</a>
		<?php endif; ?>

		<?php if ($times[$task['Task']['id']]['Time']['status'] == 'pause') : ?>
		<a class="left" href="/times/play/<?php echo $task['Task']['id']; ?>/<?php echo base64_encode($this->params['url']['url']); ?>" title="Play">
			<img src="/img/control_play.png" style="height: 18px; margin: 2px 4px 0 1px;"/>
		</a>
		<?php endif; ?>

		<a class="left" href="/times/stop/<?php echo $task['Task']['id']; ?>/<?php echo base64_encode($this->params['url']['url']); ?>" title="Stop">
			<img src="/img/control_stop.png" style="height: 18px; margin: 2px 4px 0 1px;"/>
		</a>

	<?php elseif($task['Task']['status'] != 'closed') : ?>
		<a class="left" href="/times/play/<?php echo $task['Task']['id']; ?>/<?php echo base64_encode($this->params['url']['url']); ?>" title="Play">
			<img src="/img/control_play.png" style="height: 18px; margin: 2px 4px 0 1px;"/>
		</a>
	<?php endif; ?>
</span>
<script>
	setInterval(function(){
		minutes = $(".minutes").text();
		minutes++;
		$(".minutes").text(minutes);
		
		hours = minutes/60 - (minutes/60) % 1;
		hours = ((hours+"").length == 1) ? "0"+hours : hours;
		minutes = minutes % 60;
		minutes = ((minutes+"").length == 1) ? "0"+minutes : minutes
		$(".time").text(hours + ":" + minutes);
	}, 60*1000);
</script>
<?php endif; ?>